package cn.xiongxf.feignclient;

import cn.xiongxf.domain.Movie;
import cn.xiongxf.domain.User;
import cn.xiongxf.domain.UserMovie;
import cn.xiongxf.util.AjaxResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Component
public class MovieFeignClientFallbackFactory implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        // 打印接口错误，方便查找错误
        throwable.printStackTrace();
        return new MovieFeignClient() {
            @Override
            public AjaxResult add(User user){
                return new AjaxResult(false,"服务熔断触发,Movie服务不可用！");
            }

            @Override
            public List<Movie> findAll() {
                return null;
            }

            @Override
            public AjaxResult purchase(UserMovie userMovie) {
                return new AjaxResult(false,"服务熔断触发,Movie服务不可用！");
            }

            @Override
            public BigDecimal queryPrice(Long id) {
                return null;
            }

            @Override
            public void presented(Long id) {

            }

            @Override
            public AjaxResult watch(UserMovie userMovie) {
                return null;
            }
        };
    }
}
